import entity.Employee;
import func.Function01;
import func.Function02;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by VincentZee on 2019/3/2
 */
public class TestLambda00 {
    List<Employee> employeeList = Arrays.asList(
            new Employee(101, "张三", 18, 9999.99),
            new Employee(102, "李四", 59, 6666.66),
            new Employee(103, "王五", 28, 3333.33),
            new Employee(104, "赵六", 8, 7777.77),
            new Employee(105, "田七", 38, 5555.55)
    );

    @Test
    public void test01() {
        Collections.sort(employeeList, (e1, e2) -> {
            if (e1.getAge() == e2.getAge()) {
                return e1.getName().compareTo(e2.getName());
            } else {
                return Integer.compare(e1.getAge(), e2.getAge());
            }
        });

        for (Employee employee : employeeList) {
            System.out.println(employee);
        }
    }

    @Test
    public void test02() {
        String trimStr = strHanlder("\t\t   niubility  ", (str) -> str.trim());
        System.out.println(trimStr);

        String upperStr = strHanlder("asdb", (str) -> str.toUpperCase());
        System.out.println(upperStr);

        String subStr = strHanlder("helloworld", (str) -> str.substring(1, 3));
        System.out.println(subStr);
    }

    // 字符串处理器
    public String strHanlder(String str, Function01 function01) {
        return function01.getValue(str);
    }

    @Test
    public void test03() {
        longHanlder(100L, 200L, (x, y) -> x + y);
        longHanlder(100L, 200L, (x, y) -> x * y);
    }

    // Long数据处理
    public void longHanlder(Long l1, Long l2, Function02<Long, Long> function02) {
        Long res = function02.getValue(l1, l2);
        System.out.println(res);
    }
}
